package com.example.bykc.demos.service;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.example.bykc.demos.pojo.pojo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.core.io.ClassPathResource;
import org.springframework.stereotype.Component;

import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.util.ArrayList;
import java.util.List;

/**
 * @author wzh
 * @date 2024/5/24
 * @apiNote
 */
@Component
@Slf4j
public class service {

    public List process() {
        File file = null;
        try {
            file = new ClassPathResource("json/a.json").getFile();
        } catch (IOException e) {
            log.warn("文件未读取到");
            throw new RuntimeException(e);
        }
        String jsonContent = null;
        ArrayList<pojo> result = new ArrayList<>();
        try {
            jsonContent = new String(Files.readAllBytes(file.toPath()));
            JSONArray jsonArray = JSON.parseArray(jsonContent);

            for (int i = 0; i < jsonArray.size(); i++) {
                JSONObject jsonObject = jsonArray.getJSONObject(i);
                pojo pojoInstance = new pojo(jsonObject.getInteger("bno"), jsonObject.getInteger("stat"),
                        jsonObject.getInteger("side"), jsonObject.getInteger("size"),
                        jsonObject.getInteger("lock"), jsonObject.getInteger("type"));
                result.add(pojoInstance);
            }






        } catch (IOException e) {
            throw new RuntimeException(e);
        }
        return result;
    }


}
